package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Wawebnews;
import com.ruoyi.system.service.IWawebnewsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 新闻内容Controller
 * 
 * @author ruoyi
 * @date 2024-03-17
 */
@Controller
@RequestMapping("/system/wawebnews")
public class WawebnewsController extends BaseController
{
    private String prefix = "system/wawebnews";

    @Autowired
    private IWawebnewsService wawebnewsService;

    @RequiresPermissions("system:wawebnews:view")
    @GetMapping()
    public String wawebnews()
    {
        return prefix + "/wawebnews";
    }

    /**
     * 查询新闻内容列表
     */
    @RequiresPermissions("system:wawebnews:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Wawebnews wawebnews)
    {
        startPage();
        List<Wawebnews> list = wawebnewsService.selectWawebnewsList(wawebnews);
        return getDataTable(list);
    }

    /**
     * 导出新闻内容列表
     */
    @RequiresPermissions("system:wawebnews:export")
    @Log(title = "新闻内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Wawebnews wawebnews)
    {
        List<Wawebnews> list = wawebnewsService.selectWawebnewsList(wawebnews);
        ExcelUtil<Wawebnews> util = new ExcelUtil<Wawebnews>(Wawebnews.class);
        return util.exportExcel(list, "新闻内容数据");
    }

    /**
     * 新增新闻内容
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存新闻内容
     */
    @RequiresPermissions("system:wawebnews:add")
    @Log(title = "新闻内容", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Wawebnews wawebnews)
    {
        return toAjax(wawebnewsService.insertWawebnews(wawebnews));
    }

    /**
     * 修改新闻内容
     */
    @RequiresPermissions("system:wawebnews:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Wawebnews wawebnews = wawebnewsService.selectWawebnewsById(id);
        mmap.put("wawebnews", wawebnews);
        return prefix + "/edit";
    }

    /**
     * 修改保存新闻内容
     */
    @RequiresPermissions("system:wawebnews:edit")
    @Log(title = "新闻内容", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Wawebnews wawebnews)
    {
        return toAjax(wawebnewsService.updateWawebnews(wawebnews));
    }

    /**
     * 删除新闻内容
     */
    @RequiresPermissions("system:wawebnews:remove")
    @Log(title = "新闻内容", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wawebnewsService.deleteWawebnewsByIds(ids));
    }
}
